package com.hmall.order.mq;



import com.hmall.order.constants.MQConstants;
import com.hmall.order.service.impl.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Ms SUN
 * @date 2023/5/15
 */
@Slf4j
@Component
public class OrderListener {
    @Resource
    private OrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.QUEUE_NAME_DELAY),
            exchange = @Exchange(name =MQConstants.EXCHANGE_NAME ,type = ExchangeTypes.TOPIC),
            key =MQConstants.ROUTING_KEY_DELAY
    ))
    public void listenOrderCancel(String id){
        log.info("监听超时取消订单消息:{}",id);
        orderService.cancelOrder(Long.valueOf(id));
    }
}
